package org.nowcoder.leetcode.BSearch;

import java.util.Arrays;

/**
 * Title  : 35. Search Insert Position
 * Source : https://leetcode.cn/problems/search-insert-position/description/
 * Author : XrazYang
 * Date   : 2023-10-30
 */

public class LeetCode_35 {
    public int searchInsert(int[] nums, int target) {
        /**
         * 查找元素不存在时，binarySearch方法返回值:
         * (-(insertion point) - 1)
         */
        int i = Arrays.binarySearch(nums, target);
        return i >= 0 ? i : (-i - 1);
    }
}
